#include "stdafx.h"
#include "MLConsolePrinter.h"


#define MLPRINT_COLOR_DEBUG   (FOREGROUND_INTENSITY | FOREGROUND_GREEN)
#define MLPRINT_COLOR_ERROR   (FOREGROUND_INTENSITY | FOREGROUND_RED)
#define MLPRINT_COLOR_CONSOLE (FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)

CMLConsolePrinter::CMLConsolePrinter(void)
{
}

CMLConsolePrinter::~CMLConsolePrinter(void)
{
}

void CMLConsolePrinter::PrintError(const wchar_t *fmt, ...)
{
	WCHAR buf[MAX_PRINT_LENGTH];

	va_list args;
	va_start(args, fmt);

	vswprintf_s(buf, MAX_PRINT_LENGTH, fmt, args);

	HANDLE consoleHandle = ::GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(consoleHandle, MLPRINT_COLOR_ERROR);

	std::wcout << buf;
	std::wcout.flush();

	SetConsoleTextAttribute(consoleHandle, 
		FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

	va_end(args);
}

void CMLConsolePrinter::PrintDebug(const wchar_t *fmt, ...)
{
	WCHAR buf[MAX_PRINT_LENGTH];

	va_list args;
	va_start(args, fmt);

	vswprintf_s(buf, MAX_PRINT_LENGTH, fmt, args);

	HANDLE consoleHandle = ::GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(consoleHandle, MLPRINT_COLOR_DEBUG);

	std::wcout << buf;
	std::wcout.flush();

	SetConsoleTextAttribute(consoleHandle, 
		FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

	va_end(args);
}

void CMLConsolePrinter::PrintConsole(const wchar_t *fmt, ...)
{
	WCHAR buf[MAX_PRINT_LENGTH];

	va_list args;
	va_start(args, fmt);

	vswprintf_s(buf, MAX_PRINT_LENGTH, fmt, args);

	HANDLE consoleHandle = ::GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(consoleHandle, MLPRINT_COLOR_CONSOLE);

	std::wcout << buf;
	std::wcout.flush();

	SetConsoleTextAttribute(consoleHandle, 
		FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

	va_end(args);
}
